﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace ĐỒ_ÁN_QLDA
{
    public partial class frmTimkiemgiaovien : Form
    {
        String conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataAdapter da;
        DataSet ds;

        public frmTimkiemgiaovien()
        {
            InitializeComponent();
        }

        private void frmTimkiemgiaovien_Load(object sender, EventArgs e)
        {
            ds = new DataSet();
            conn = new SqlConnection(conStr);
            conn.Open();
            cmd = new SqlCommand("Select * from Giaovien", conn);
            da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Giaovien");
            dataGridView1.DataSource = ds.Tables[0];
            conn.Close();
        }

              private void bntSearch_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbTimkiem.SelectedItem.ToString() == "Tìm kiếm giáo viên theo mã giáo viên ")
                {
                    ds.Tables[0].DefaultView.RowFilter = "MaGiaoVien like\'%" + txtTimkiem.Text + "%\'";
                }
                else if (cmbTimkiem.SelectedItem.ToString() == "Tìm kiếm giáo viên theo tên giáo viên")
                {
                    ds.Tables[0].DefaultView.RowFilter = "TenGiaoVien like\'%" + txtTimkiem.Text + "%\'";
                }
            }
            catch
            {
                ds.Tables[0].DefaultView.RowFilter = "MaGiaoVien like\'%" + txtTimkiem.Text + "%\'";
            }
        }

              private void bntThoat_Click(object sender, EventArgs e)
              {
                  this.Dispose();
              }

              private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
              {

              }

                      
    }
}
